package com.wxh.concurrent;

/**
 * @ClassName: ThreadExceptionQuestion
 * @Description: 线程异常问题
 * @Author wxh
 * @Date: 2021/3/18 16:26
 * @Version V1.0.0
 * @Since 1.8
 */
public class ThreadExceptionQuestion {
    public static void main(String[] args) throws InterruptedException {

        // 异常捕获
        Thread.setDefaultUncaughtExceptionHandler((thread, throwable) ->{
            System.out.printf("线程[%s] 遇到异常，详细信息是 %s \n ", thread.getName(), throwable.getMessage());
        });

        Thread t1 = new Thread(()->{
            throw new RuntimeException("数据达到阈值");
        }, "t1");

        t1.start();
        // main线程不会终止
        t1.join();
        // java中 Thread是一个包装, 有GC来垃圾回收
        // jvm thread 时刻一个os 线程 ，jvm管理
        System.out.println(t1.isAlive());
    }
}
